﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Moving03.Classes;

namespace Moving03
{
    public partial class WebForm3 : BasePage
    {
        string Email;
        protected void Page_Load(object sender, EventArgs e)
        {
            ValidationSummary1.ValidationGroup = CreateUserWizard1.UniqueID;
           
        }

        protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
        {
            Email = CreateUserWizard1.Email;
        }

        protected void CreateUserWizard1_FinishButtonClick(object sender, WizardNavigationEventArgs e)
        {
            TextBox UserNameTextBox =(TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("UserName");

            TextBox EmailTextBox = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("Email");
            SqlDataSource DataSource =
                (SqlDataSource)CreateUserWizardStep2.FindControl("InsertExtraInfo");

            MembershipUser User = Membership.GetUser(UserNameTextBox.Text);

            object UserGUID = User.ProviderUserKey;

            Roles.AddUserToRole(UserNameTextBox.Text, "Member");
            DataSource.UpdateParameters.Add("Email", EmailTextBox.Text.ToString());
            DataSource.UpdateParameters.Add("UserName", UserNameTextBox.Text.ToString());
            DataSource.Update();
           
        }

        protected void CreateUserWizard1_ContinueButtonClick(object sender, EventArgs e)
        {
            
            
            
        }

        protected void CreateUserWizard1_NextButtonClick(object sender, WizardNavigationEventArgs e)
        {
           
            
        }

        protected void UserName_TextChanged(object sender, EventArgs e)
        {
            string s = e.ToString();
        }
        public static bool UserNameExists(string yourName)
        {
            return Membership.GetUser(yourName) != null;
        }

        protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
        {
            string s = args.Value;
            if (UserNameExists(s))
                args.IsValid= false;
            else
                args.IsValid = true;
        } 
        
        
    }
}